var htmlWebpachPlugin = require("html-webpack-plugin");
var extractTextWebpackPlugin = require("extract-text-webpack-plugin");
var webpack = require("webpack");
var config = require("./config/index");
module.exports = {
  entry: config.chunks,
  output: {
    path: config.buildPath,
    filename: "js/[name].js",
    publicPath: config.productionPublicPath
  },
  module: {
    rules: [
      {
        test: /\.styl$/,
        use: extractTextWebpackPlugin.extract({
          fallback: "style-loader",
          use: [
            {
              loader: "css-loader",
              options: {
                minimize: true
              }
            },
            {
              loader: "stylus-loader"
            }
          ]
        })
      },
      {
        test: /\.css$/,
        use: extractTextWebpackPlugin.extract({
          fallback: "style-loader",
          use: [
            {
              loader: "css-loader",
              // css压缩
              options: {
                minimize: true
              }
            }
          ]
        })
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              name: "css/fonts/[name].[ext]",
              limit: 8192
            }
          }
        ]
      },
      {
        test: /\.(jpg|png|gif|jpeg)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              name: "img/[name].[ext]",
              limit: 8192
            }
          }
        ]
      }
    ]
  },
  plugins: config.htmls.concat([
    new extractTextWebpackPlugin("css/[name].css"),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery",
      "window.$": "jquery"
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: "common",
      filename: "js/base.js"
    }),
    new webpack.optimize.UglifyJsPlugin()
  ])
};
